#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int N = 510;
int in[N];
vector<int> edges[N];
bool st[N];

int n;

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int x, m, y; cin >> x >> m;
		st[x] = true;
		while(m--)
		{
			cin >> y;
			edges[x].push_back(y);
			in[y]++;
		}
	}
	queue<int> q;
	for(int i = 0; i <= 500; i++)
	{
		if(st[i] && !in[i]) q.push(i);
	}
	while(q.size())
	{
		int x = q.front(); q.pop();
		for(auto t : edges[x])
		{
			in[t]--;
			if(st[t] && !in[t]) q.push(t);
		}
	}
	int ans = 0;
	for(int i = 0; i <= 500; i++)
	{
		if(st[i] && in[i]) ans++;
	}
	if(ans) cout << ans << endl;
	else cout << "YES" << endl;
	return 0;
}
